package com.dcbeida.activity.stockdetail;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;

import com.dcbeida.MyApplication;
import com.dcbeida.R;
import com.dcbeida.activity.BaseActivity;
import com.dcbeida.activity.hospital.HospitalActivity;
import com.dcbeida.activity.source_unit.SourceActivity;
import com.dcbeida.adapter.RkSocketAdapter;
import com.dcbeida.adapter.SalsesDetailRYAdapter;
import com.dcbeida.bean.Drug;
import com.dcbeida.bean.DrugListBean;
import com.dcbeida.bean.HospitalBean;
import com.dcbeida.bean.Result_Api;
import com.dcbeida.bean.SourceBean;
import com.dcbeida.bean.Stock;
import com.dcbeida.callback.DialogCallback;
import com.dcbeida.model.ModelUtils;
import com.dcbeida.utils.Constants;
import com.dcbeida.utils.JsonGet;
import com.dcbeida.widget.ListViewForScrollView;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.OnClick;

/**
 * 入存详情
 * Created by swt on 2017/9/29.
 */

public class RkStockDetailEditActivity extends BaseActivity implements RkStockDetailEditContract.View{


    @Bind(R.id.tv_bh)
    TextView tvBh;
    @Bind(R.id.tv_rksj)
    TextView tvRksj;
    @Bind(R.id.tv_djsj)
    TextView tvDjsj;
    @Bind(R.id.tv_name)
    TextView tvName;
    @Bind(R.id.tv_money)
    EditText tvMoney;
    @Bind(R.id.img_back)
    ImageView imgBack;
    @Bind(R.id.tv_title)
    TextView tvTitle;
    @Bind(R.id.tv_right)
    TextView tvRight;


    private Stock.ListBean resoursebean;

    private RkStockDetailEditContract.Present mPresent;

    @Override
    protected int getLayoutResId() {
        return R.layout.rk_detail_edit;
    }

    @Override
    public void setData() {
        mPresent = new RkStockDetailEditPresenter(this, this);
        tvTitle.setText("修改入库详情");
        tvRight.setText("提交");
        imgBack.setVisibility(View.VISIBLE);

        Bundle bundle = getIntent().getExtras();
        if (null != bundle) {
            resoursebean = (Stock.ListBean) bundle.getSerializable("Stock.ListBean");
            tvBh.setText(resoursebean.getStockinlogid());
            tvRksj.setText(mContext.getString(R.string.rksj2) + resoursebean.getAddstocktime());
            tvDjsj.setText(mContext.getString(R.string.djsj2) + resoursebean.getDeliverytime());
            tvName.setText(resoursebean.getProvider());
            tvMoney.setText( resoursebean.getInvoicemoney());
        }


    }


    @OnClick({R.id.img_back,R.id.tv_right,R.id.ll_yymc})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.img_back:
                finish();
                break;
            case R.id.ll_yymc:
               Bundle b = new Bundle();
                showActivityForResult(SourceActivity.class, b, Constants.HOSPITAL_TYPE);
                break;
            case R.id.tv_right:
                if(TextUtils.isEmpty(tvMoney.getText().toString())){
                    showTip("请填写发票金额");
                    return;
                }
                mPresent.modifyDetail(resoursebean.getStockinlogid(),
                        resoursebean.getProvider(),resoursebean.getProviderid(),tvMoney.getText().toString());
                break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == Constants.HOSPITAL_TYPE && resultCode == RESULT_OK) {//选择医院
            Bundle bundle = data.getExtras();
            if (null != bundle) {
                if (bundle.containsKey("sourceBean")) {
                    SourceBean sourceBean = (SourceBean) bundle.getSerializable("sourceBean");
                    resoursebean.setProvider(sourceBean.getProvidername());
                    resoursebean.setProviderid(String.valueOf(sourceBean.getProviderid()));
                    tvName.setText(resoursebean.getProvider());

                }
            }
        }
    }

    @Override
    public void setPresenter(RkStockDetailEditContract.Present presenter) {

    }

    @Override
    public void confimSuccess() {
        resoursebean.setInvoicemoney(tvMoney.getText().toString());
        Intent intent = new Intent();
        intent.putExtra("bean", resoursebean);
        setResult(Activity.RESULT_OK, intent);
        finish();
    }

    @Override
    public void showTelTip(String msg) {

    }
}
